@extends('layouts.admin')
@section('title') @parent 修改圈子 @stop
@section('page_title')@parent
修改圈子
@show
@section('breadcrumb')@parent
{{ Breadcrumbs::render('circle-edit') }}
@show
@section('content')
<div class="row">
		@include('widgets.notification')
		<div class="col-md-12">
				<!-- general form elements -->
				<div class="box box-primary">
						<div class="box-header">
								<h3 class="box-title">修改圈子</h3>
						</div>
						<form for="form" class="" autocomplete="off" method="post" action="{{ route('admin.circle.edit', $circle->id) }}" enctype="multipart/form-data" id="form-coupon">
						<input type="hidden" name="_token" value="{{ csrf_token() }}" />
						<div class="box-body">								
								

								<div class="form-group">
										<label for="group_name">圈子标题</label>
										<input name="group_name" id="group_name" class="form-control" placeholder="圈子标题" value="@if(Input::old('group_name')){{ Input::old('group_name') }}@else{{ $circle->group_name }}@endif" required>
										{{ $errors->first('title', '<strong class="error">:message</strong>') }}
								</div>								
								<div class="form-group">
										<label for="group_intro">圈子简介</label>
										<textarea cols="50" rows="5" name="group_intro" id="group_intro" class="form-control">@if(Input::old('group_intro')){{ Input::old('group_intro') }}@else{{ $circle->group_intro }}@endif</textarea>
								</div>
								<div class="form-group">
										<label for="work_scope">圈子范围</label>
										<textarea cols="50" rows="5" name="work_scope" id="work_scope" class="form-control">@if(Input::old('work_scope')){{ Input::old('work_scope') }}@else{{ $circle->work_scope }}@endif</textarea>
								</div>

								
								<div class="form-group">
										<label>缩略图</label>
										<div class="controls">
											<div class="input-group">
												 <input class="input-file" name="group_avatar" type="file">
											</div>
										</div>
										@if($circle->group_avatar)<img src="{{ asset($circle->group_avatar) }}" style="width:200px;">@endif
								</div>

								<div class="form-group">
										<label for="class">地址</label>
										<select name="province" id="field_province" default="{{ $circle->province }}"></select>
										<select name="city" id="field_city" default="{{ $circle->city }}"></select>
										<select name="district" id="field_district" default="{{ $circle->district }}"></select>
								</div>
								<div class="form-group">
										<label>是否推荐</label>
										<div class="radio">
											<label>
						                    <input type="radio" name="is_recommended" id="option1" autocomplete="off" @if ($circle->is_recommended) checked @endif value="1"> 是
						                 	</label>

						                 	<label>
						                     <input type="radio" name="is_recommended" id="option2" autocomplete="off" @if (!$circle->is_recommended) checked @endif value="0"> 否
											</label>
						                </div>
								</div>


													
						</div>
						<div class="box-footer">
								<a href="{{ route('admin.circle.index') }}" class="btn btn-default btn-save">返 回</a>
								<button type="submit" class="btn btn-primary btn-save">保 存</button>
						</div>
						</form>
				</div>
		</div>
</div>
@stop
@section('end')
    @parent
{{ HTML::script("js/jquery-ui-1.11.1.min.js") }}
<script>
var area_data = {};

  $(document).on('change','#field_province', function(){
	var val = $(this).val();
	$(this).attr('default','');
	$('#field_city').html('');
	$('#field_district').html('');
	var city_ele = $('#field_city');
	var defval = '';
	if (val != '') {
	  defval = val.replace(/0000$/,'');
	}else{
	  return;
	}
	for (var key in area_data) {
	  var k = String(key);
	  if ( k.indexOf('00')==4 && k.indexOf(defval)===0 ) {
		var op = document.createElement('option');
		op.value = k, op.innerHTML = area_data[k];
		if ( $('#field_city').attr('default') && $('#field_city').attr('default') == k  ) {
		  op.selected = true;
		}
		city_ele.append(op);
	  }
	}
	city_ele.attr('default','')
	city_ele.trigger('change');
  });
   $(document).on('change','#field_city', function(){
	var val = $(this).val();
	$(this).attr('default','');
	$('#field_district').html('');
	if (val != '') {
	  defval = val.replace(/00$/,'');
	}else{
	  return;
	}
	var district_ele = $('#field_district');
	for (var key in area_data) {
	  var k = String(key);
	  if ( k.indexOf(defval) === 0 && k.substr(-2)!='00' ) {
		var op = document.createElement('option');
		op.value = k, op.innerHTML = area_data[k];
		if ( $('#field_district').attr('default') && $('#field_district').attr('default') == k  ) {
		  op.selected = true;
		}
		district_ele.append(op);		
	  }
	}
	district_ele.attr('default','');
  });
	$.getJSON("{{ route('common.area') }}", function (data){
	  area_data = data;
	  var province_ele = $('#field_province');
	  for (var key in area_data) {
		var k = String(key);
		if ( k.indexOf('0000') == 2)  {
		  var op = document.createElement('option');
		  op.value = k, op.innerHTML = area_data[k];
		  if ( province_ele.attr('default') &&  province_ele.attr('default') == k ) {
			op.selected = true;
		  }
		  province_ele.append(op);
		}
		
	  }
	  if ( province_ele.attr('default')) {
		$('#field_province').trigger('change');
	  }
	  
	});

</script>
@stop